# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Thomas Weißschuh <thomas@t-8ch.de>

pkgname=smlnj
pkgver=110.99.4
pkgrel=1
pkgdesc='Standard ML compiler from New Jersey'
url='https://www.smlnj.org/'
license=(BSD)
arch=(loong64 x86_64)
makedepends=(smlnj)
provides=(sml)
install=smlnj.install
_url="http://smlnj.cs.uchicago.edu/dist/working/$pkgver/"
source=(
  "$pkgname-$pkgver-boot.amd64-unix.tgz::${_url}boot.amd64-unix.tgz"
  "$pkgname-$pkgver-boot.x64-unix.tgz::${_url}boot.x86-unix.tgz"
  "$pkgname-$pkgver-config.tgz::${_url}config.tgz"
  "$pkgname-$pkgver-cm.tgz::${_url}cm.tgz"
  "$pkgname-$pkgver-compiler.tgz::${_url}compiler.tgz"
  "$pkgname-$pkgver-runtime.tgz::${_url}runtime.tgz"
  "$pkgname-$pkgver-system.tgz::${_url}system.tgz"
  "$pkgname-$pkgver-MLRISC.tgz::${_url}MLRISC.tgz"
  "$pkgname-$pkgver-smlnj-lib.tgz::${_url}smlnj-lib.tgz"
  "$pkgname-$pkgver-ckit.tgz::${_url}ckit.tgz"
  "$pkgname-$pkgver-nlffi.tgz::${_url}nlffi.tgz"
  "$pkgname-$pkgver-cml.tgz::${_url}cml.tgz"
  "$pkgname-$pkgver-ml-lpt.tgz::${_url}ml-lpt.tgz"
  "$pkgname-$pkgver-ml-lex.tgz::${_url}ml-lex.tgz"
  "$pkgname-$pkgver-ml-yacc.tgz::${_url}ml-yacc.tgz"
  "$pkgname-$pkgver-ml-burg.tgz::${_url}ml-burg.tgz"
  "$pkgname-$pkgver-trace-debug-profile.tgz::${_url}trace-debug-profile.tgz"
  urlgetter.sh
  profile.d-smlnj.sh
  smlnj.sh
)
b2sums=('81e88ecc65455ce29147130b9b848ba95e64cec184ca3c04020766eeff3bf17b4c8937d105d71748155e71cc5ae1e59a8630b9547123aa554674eba4d8f6b148'
        '689bedd368396fcf5fef27c109e43bd32a3042fda9d9cfb85905639973a6a41fcdd5829903d79745a62de9fd47ddb89a91b838a4f96e6bc26f5e2c8959b6df5c'
        'e53f3fdd61047cdb14b1cf41f2a9d7aaf024c5ac7189b592dde1ce9bb1a3b851da10e736dcbce00c3c31719f32a169343b973fd6618ee16ee9c398000b019b3c'
        'fa3fdd023d999e723b588e8edc14f5a92e6393691646b55208e23197d1a13be098a392c77bfc867c52ae2085cd08e818dcfc44096c8d4613eeaca57f7d142a56'
        'fb073628cdadc800d4dd8d1ef66c54fe500d1aa46e38005d37702f3c7381cdaf8bdf11839f319f9f1c9a7de09d832440cb525effe90b9d603889b5bb6fa189f4'
        '61dae19bfa0f48533b9def27e971566032bdbc01ba54d5300643a668e5be86e2064aefcc93c31e074cd9fa04e1af719b3c5aa98529dc8f17629d704e3a1e712b'
        '61ecb598b2daeefcd62ff8214579ecf30434368fb3b3d75edc2b701170ed9719b9f1bc8114c440ab3582329e5e965b3d1fc4287be0226707766bfc796db49fcf'
        '6d01d0a994ded4167e7429ac4d7a7184197a76b454c7270de8c0887a1a38fffc13db7c1ec23a2e26c3ee765de590cb9483ff74ef944ff71a6ed45dfab9b4c268'
        'a1adc247c82dde766a34026a2cef77b4b89cc80f52b4a949173910d30aae2a8a28dc716691c7248d145791c81c27aae75f9b5a91cdcdd3397f1f944255c50c60'
        'f1562b39a7c3560aa6907ec7358beedc033c6be75d0cb6a48ceef0a4c1c59ab8dbc8585a107415e0fcff40fc20c1943f4ba0533bc05e11078a26e089ea793512'
        'ae5d170784cc604216f9abc1d2a996002cbef333525cce5ee94a0053a3a65f62d415d9abc0b74f0337fae7dc120a6278a223872a1b39f2b22a6f931f044da57b'
        '48151b69fc020250656389c0b073bc75fd3673f21272bafd466aa966cadc3ba21f7f4de1677a4a6979b213ac5aff5bb354657516b014f9bc998a2d72d99c0e15'
        '7a2640d7dcec0303fabf8323a8e1939ff743dd057757fb712bc09c6aa5f8466752b1eed715a5568c445bcb36dd44a965424a260ef6f210c452ba59c62420244d'
        '26c5fbfb845288db2d60961565cc374f56d739fe16dcfb39b091452d6ba7c01c70772d57bf7252cb9aba44ee152dcf67e92e8fae1350f7b6a023b9a47d311472'
        '12efc1b8673a51566915d78ddfeed31e69494dcf88464d3231cedb2d4f811b86025ba7d535fb2f605b9cabef8e6a466691803f8bf7daa8a52ae5fae4b118f4a3'
        '7cdae677c454a5cfde6f914e974bce7b632a1028aaad36d8e8afaa48f07a0b9a787142ecf0c58a22c769ff5dc7a6b37c028bbb409e455fd4a45d756e70811ab0'
        '81cec5f57efc4345a287b5a0b5d93ee96271c2494feb06df3c4583bf23e6079322e9f93e0092469a233954ab145e7e6d56b821bf8bffb85c8d92338ad0fd7163'
        '6ed6fe0fa9e9dc520e25236dd0002f46eaf243b9a190a61c0f24b3bf20db8127147abd6a84290a81513110b0b7d080e9c4bcb445908f40a8cec67442f4bdbfc1'
        '3666f88b0c79022e52108073a8b6ce96520a31dba27bb3fc101518182244d03ec22eaa8719a7c08c6960ac1c867b885c58f116c04c5da1b7c7aa5e699b0e9b29'
        '619d1d3736750ace9ca4097ec137e10ab3914f905220b54156ea58bb2cf2e0e5cec8ef41e61c03d7c0f0577f4db085c4298ea075dad6c50d206e1d275ff8a981')

build() {
  mkdir -p install
  unset SMLNJ_HOME MAKEFLAGS
  export srcdir
  export pkgver
  export INSTALLDIR="$srcdir/install"
  export CFLAGS="$CFLAGS -Wl,-z,relro,-z-now"
  export LDFLAGS="$LDFLAGS -Wl,-z,relro,-z-now"
  URLGETTER="$srcdir/urlgetter.sh"
  config/install.sh -default 64
}

package() {
  install -d "$pkgdir/usr/"{lib/smlnj,share}
  install -Dm755 "$srcdir/profile.d-smlnj.sh" "$pkgdir/etc/profile.d/smlnj.sh"
  install -Dm644 compiler/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  cp -R "$srcdir/install/"{bin,lib} "$pkgdir/usr/lib/smlnj"
  cp -R "$srcdir/doc/man" "$pkgdir/usr/share/"
  find "$pkgdir/usr/share/man" -name '._*' -delete
  install -Dm755 smlnj.sh "$pkgdir/usr/bin/smlnj"
}
